package com.design.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;

/**
 * 模拟调用redis
 * @author ytj
 * @date 2021/12/23
 */
public class RedisUtil {
    private Logger logger=LoggerFactory.getLogger(RedisUtil.class);

    private Map<String,String> dataMap=new ConcurrentHashMap<>();

    public void set(String key,String value){
        logger.info("redis写入数据 key:{} val:{}",key,value);
        dataMap.put(key, value);
    }

    public String get(String key){
        logger.info("redis读取数据 key:{}",key);
        return dataMap.get(key);
    }

    public void set(String key, String value, Long timeOut, TimeUnit timeUnit){
        logger.info("redis写入数据 key:{},value:{},timeOut:{},timeUnit:{}",key,value,timeOut,timeUnit);
        dataMap.put(key, value);
    }

    public void del(String key){
        logger.info("redis删除数据 key:{}",key);
        dataMap.remove(key);
    }
}
